package com.shumei.servlet.productservlet;

import com.shumei.DAO.ProductDAO;
import com.shumei.DAO.impl.ProductDAOImpl;
import com.shumei.pojo.Product;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
@WebServlet("/index")
public class ProductIndex extends HttpServlet {
    ProductDAO productDAO = new ProductDAOImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        req.setCharacterEncoding("utf-8");
        List<Product> productlist = productDAO.getProductList();
        String html = "";
        for (int i = 0; i < productlist.size(); i++)
            html += "<h1>" + productlist.get(i).getPname() + "<h1>";
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().print(html);
    }


}